//
//  HYTabBarViewController.m
//  Around
//
//  Created by 华谕 on 2017/6/14.
//  Copyright © 2017年 HUYU. All rights reserved.
//

#import "HYTabBarViewController.h"
#import "HYNavBaseViewController.h"
#import "HomePageViewController.h"
//#import "TechnicalViewController.h"
#import "ShopCarHomeViewController.h"
#import "LiveHomeViewController.h"
#import "PersonalViewController.h"
#import "PreferenceAreaViewController.h"

#define IOS7   [[UIDevice currentDevice]systemVersion].floatValue>=7.0
@interface HYTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation HYTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.delegate = self;
    
    PreferenceAreaViewController *technicalVc = [[PreferenceAreaViewController alloc] init];
    [self setupOneChildViewController:technicalVc title:@"特惠区" image:@"techUn" selectedImage:@"techSel"];

    LiveHomeViewController *liveVc = [[LiveHomeViewController alloc] init];
    [self setupOneChildViewController:liveVc title:@"生活区" image:@"liveUn" selectedImage:@"liveSel"];
    
    HomePageViewController *HomeVC = [[HomePageViewController alloc]init];
    [self setupOneChildViewController:HomeVC title:@"生产区" image:@"productUn" selectedImage:@"productSel"];
    
    ShopCarHomeViewController *shopcarVc = [[ShopCarHomeViewController alloc] init];
    [self setupOneChildViewController:shopcarVc title:@"购物车" image:@"gouwuche-" selectedImage:@"gouwuche"];
    
    PersonalViewController *personVc  = [[PersonalViewController alloc] init];
    [self setupOneChildViewController:personVc title:@"个人中心" image:@"personUn" selectedImage:@"personSel"];

    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, TABBAR_HEIGHT)];
    //    backView.backgroundColor = [UIColor blackColor];
    [self.tabBarController.tabBar insertSubview:backView atIndex:0];
    self.tabBarController.tabBar.opaque = YES;
    [UITabBar appearance].translucent = NO;

    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];



    
    
    
    
    
    
}

- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    vc.tabBarItem.title = title;
    // 设置子控制器的图片
    vc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    [UIImage imageNamed:image];
    if (IOS7) {
        vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    } else {
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    }
    
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:ThemeColor} forState:UIControlStateSelected];
    
    //    [self addChildViewController:vc];
    
    // 先给外面传进来的小控制器 包装 一个导航控制器
    HYNavBaseViewController *nav = [[HYNavBaseViewController alloc] initWithRootViewController:vc];
    // 添加为子控制器
    [self addChildViewController:nav];
    
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    
//    if(viewController == [tabBarController.viewControllers objectAtIndex:2])
//    {
//        if (![LTools storageForKey:SERVER_IsLogin]) {
    
//            LoginViewController *loginVC = [[LoginViewController alloc] init];
//            //nav化
//            HYNavBaseViewController *navVC = [[HYNavBaseViewController alloc] initWithRootViewController:loginVC];
//            [self presentViewController:navVC animated:YES completion:nil];
//            return NO;
//        }
//
//
//    }

    
    
    
    
    return YES;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
